package controller;

import java.awt.Color;
import java.awt.Font;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.swing.JLabel;
import javax.swing.JPanel;

import types.ConsoleType;


@SuppressWarnings("serial")
public class Console extends JPanel {

	// singleton van gemaakt
	private static Console single;

	JLabel JConsole;

	public Console() {
		JConsole = new JLabel("Hier komen alle meldingen.");
		JConsole.setForeground(Color.YELLOW);
		add(JConsole);
	}
	/*
	 * @param message 
	 */
	// Sets the colors for the console message. ConsoleType is de enum in de package 'types'
	public void setConsole(String message, ConsoleType type) {
		String stringDate = "";
		DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
		Date date = new Date();
		switch (type) {

		default:
			JConsole.setForeground(Color.YELLOW);
			break;
		case ERROR:
			JConsole.setForeground(Color.RED);
			break;
		case SUCCESS:
			JConsole.setForeground(Color.GREEN);
			stringDate = dateFormat.format(date) + " - ";
			break;
		case REFRESH:
			JConsole.setForeground(Color.YELLOW);
			stringDate = dateFormat.format(date) + " - ";
			break;
		case EMPTY:
			JConsole.setForeground(Color.CYAN);
			break;
		}
		
		// lettertype en lettergrootte instellen
	    Font myFont = new Font("Serif", Font.BOLD, 12);
		JConsole.setFont(myFont);

		// het daadwerkelijk vervangen van de tekst in de console
		JConsole.setText(stringDate + message);
		
	
	}

	public JLabel getJConsole() {
		return JConsole;
	}

	public void setJConsole(JLabel jConsole) {
		JConsole = jConsole;
	}

	public static Console getInstance() {
		if (single == null) {
			single = new Console();
		}
		return single;
	}
}
